<template>
    <div>
        <table class="table">
            <tr>
                <td>房号名称</td>
                <td><input type="text" v-model="dataa.houseNumName"></td>
            </tr>

            <tr>
                <td>房型名称</td>
                <select v-model="dataa.houseTypeId">
                    <option value="0">请选择</option>
                    <option :value="a.houseTypeId" v-for="a in ps">{{a.houseTypeName}}</option>
                </select>
            </tr>

            <tr>
                <td>是否入住</td>
                <td>
                    <input type="radio" :value="1" v-model="dataa.houseState">空闲
                    <input type="radio" :value="2" v-model="dataa.houseState">已入住

                </td>
            </tr>

            <tr>
                <td></td>
                <td><input type="button" value="修改" @click="Add"></td>
            </tr>

        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';
import { useRouter } from 'vue-router';
import { useRoute } from 'vue-router';
const route = useRoute();
const router = useRouter();
onMounted(()=>{
    Bang();
    getDate();
})

const dataa = ref({
  "houseNumId": 0,
  "houseNumName": "",
  "states": true,
  "createTime": "2025-08-07T05:41:13.099Z",
  "houseTypeId": 0,
  "houseState": 0
})

const Add=()=>{
    axios.post("https://localhost:7189/api/House/Update",dataa.value).then((res)=>{
        if(res.data == -1)
        {
            alert("用户名存在!");
            return;
        }
        if(res.data>0)
        {
            alert("修改成功");
            router.push("/ShowNumView")
        }
        else
        {
            alert("修改失败")
        }
    })
}

const getDate=()=>{
    let val = route.query.id;
    axios.get("https://localhost:7189/api/House/Fan",{params:{id:val}}).then((res)=>{
        dataa.value = res.data;
    })
}

const ps = ref([{
    "houseTypeId": 0,
    "houseTypeName": "",
    "houseTypeImg": "",
    "houseTypeArear": 0,
    "houseTypeState": 0
}])

const Bang=()=>{
    axios.get("https://localhost:7189/api/HouseType/ShowAll").then((res)=>{
        ps.value = res.data;
    })
}

</script>

<style scoped>

</style>